package org.lee.pattern.observer;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * SubjectHandler
 * 监听者容器实现
 *
 * @author dralee
 * @date 2022-03-09 10:17:05
 **/
public class SubjectHandler implements Subject {
    private static final List<Observer> SUBJECTS = Collections.synchronizedList(new LinkedList<>());

    @Override
    public void add(Observer observer) {
        SUBJECTS.add(observer);
    }

    @Override
    public void notifyAllSubject() {
        SUBJECTS.forEach(Observer::exceptionHandler);
    }
}
